package com.sentiment.sinalgo;



import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.w3c.dom.NodeList;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;

/**
 * Created by  vani:liaozhenlin on 15-10-19.
 * If you meet any question,you can email at 939899727@qq.com
 * @author 廖贞林  from uestc
 */
public class LoadConfigurationXMLFile {
    
	public static String userDir = System.getProperty("user.dir");
	
    public LoadConfigurationXMLFile(){
    }
    private static SAXReader saxReader=new SAXReader();
    
    public static String loadLocalPath(String filePath){
    	Document doc;
        Element root;
        try{
            doc=saxReader.read(new FileInputStream(new File(filePath)));
            root=doc.getRootElement();
            Element e = root.element("local");
            Element foo = e.element("path");
            return foo.getText();
            
        }catch (Exception e){
        	System.out.println(e.toString());
        }
        return null;
    }
    
    public static ArrayList loadSinaPara(String filePath){
        Document doc;
        Element root;
        ArrayList<String> arr = new ArrayList();
        try{
            doc=saxReader.read(new FileInputStream(new File(filePath)));
            root=doc.getRootElement();
            Element e = root.element("sina");
            Element foo;

            for (Iterator i = e.elementIterator(); i.hasNext();){
                foo = (Element) i.next();
                String temp = foo.getText();
                arr.add(temp);
            }
            
        }catch (Exception e){
        	System.out.println(e.toString());
        }
        System.out.println(arr);
        return arr;
    }
    
    public static void main(String[] args){
    	String path = System.getProperty("user.dir")+"\\WebContent\\para.xml";
    	
//    	LoadConfigurationXMLFile.loadSinaPara(path);
    	
    	System.out.println(LoadConfigurationXMLFile.loadLocalPath(path));
    }

}
